import requests
from requests import session

from common.p2p_common import GetLog

log = GetLog.get_log()


class P2pRegister(object):

    def __init__(self):
        self.session = session()
        self.url = 'http://121.43.169.97:8081'

    def api_register_img_code(self, random):
        log.info(f"正在调用图片验证码接口,请求URL：{self.url+'/common/public/verifycode1/{}'}")
        return self.session.get(url=self.url+'/common/public/verifycode1/{}'.format(random))

    def api_register_phone_code(self, phone, imgverifycode):
        data = {
            "phone": phone,
            "imgVerifyCode": imgverifycode,
            "type": "reg"
                }

        return self.session.post(url=self.url+'/member/public/sendSms', data=data)

    def api_register(self, phone, password, verifycode, phone_code):
        data = {
            "phone": phone,
            "password": password,
            "verifycode": verifycode,
            "phone_code": phone_code,
            "dy_server": "no",
            "invite_phone": None
        }

        return self.session.post(url=self.url + '/member/public/reg', data=data)




if __name__ == '__main__':
    p2p = P2pRegister()
    p = p2p.api_register_img_code()
    print(p.text)